package com.hmall.api.config;

import com.hmall.api.client.fallback.ItemClientFallback;
import com.hmall.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @className:DefaultFeignConfig
 * @date: 2025/6/30 下午6:56
 * @description:
 */
@Configuration
public class DefaultFeignConfig {
    /**
     * 通过注册Bean来设置日志记录级别
     * @return
     */
    @Bean
    public Logger.Level feignLogLevel(){
        return Logger.Level.FULL;
    }
    @Bean
    public RequestInterceptor userInfoRequestInterceptor(){
        return requestTemplate -> {
            Long userId = UserContext.getUser();
            if(userId != null){
                return;
            }
            requestTemplate.header("user-info", String.valueOf(userId));

        };
    }
    @Bean
    public ItemClientFallback itemClientFallback(){
        return new ItemClientFallback();
    }
}
